import {Dimensions, Platform, NativeModules} from 'react-native';

const {StatusBarManager} = NativeModules;

const {width, height} = Dimensions.get('window');

let iphonexScreen = [
  //iphone x && xs && 11 && 11 pro && 12 mini && 13 mini
  {width: 375, height: 812},
  //iphone xs max && 11 pro Max
  {width: 414, height: 896},
  //iphone 12 && 12 pro & 13 & 13 pro & 14
  {width: 390, height: 844},
  //iphone 12 pro max && 13 pro max & 14 plus
  {width: 428, height: 926},
  //iphone 14 pro
  {width: 393, height: 852},
  //iphone 14 pro plus
  {width: 430, height: 932},
];

const STATUS_BAR_HEIGHT = isIphoneX() ? 44 : 20;
// const BOTTOM_SAFE_HEIGHT = isIphoneX() ? 34 : 0;

// let STATUS_BAR_HEIGHT;
// if (Platform.OS === 'ios') {
//   StatusBarManager.getHeight((height) => {
//     STATUS_BAR_HEIGHT = height;
//   });
// } else {
//   STATUS_BAR_HEIGHT = StatusBar.currentHeight;
// }

const NAVIGATION_HEIGHT = STATUS_BAR_HEIGHT + 44;

console.log('状态栏高度', STATUS_BAR_HEIGHT);
console.log('导航高度', NAVIGATION_HEIGHT);

function isIphoneX() {
  return (
    Platform.OS === 'ios' &&
    iphonexScreen.some((item) => {
      return (
        (item.width == width && item.height == height) ||
        (item.width == height && item.height == width)
      );
    })
  );
}

function isAndroid() {
  return Platform.OS === 'android';
}

function getNavigationHeight() {
  if (isIphoneX()) {
    return 88;
  }
  return 64;
}

function getStatusBarHeight() {
  if (isIphoneX()) {
    return 44;
  }
  return 20;
}

const LayoutConstants = {
  WINDOW_WIDTH: width,
  WINDOW_HEIGHT: height,
  NAVIGATION_HEIGHT,
  STATUS_BAR_HEIGHT,
  isIphoneX,
  isAndroid,
};

export default LayoutConstants;
